﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using SmartWarehouse.Common;
using SmartWarehouse.ORM.Entity;
using SmartWarehouse.BussinessLogic.Basis;

public partial class AddInventory :SwBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            InitBin();
            InitLocation();
            InitMovementType();
            InitWarehouse();
        }
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        ClearMessage();

        SwTransaction trans = new SwTransaction();
        trans.Product_name = this.txtName.Text.Trim();
        trans.Cur_warehouse = this.drpWarehouse.SelectedValue;
        trans.Cur_location = this.drpLocation.SelectedValue;
        trans.Cur_bin = this.drpBin.SelectedValue;
        trans.Qty = decimal.Parse( this.txtQty.Text.Trim());
        trans.Movement_type = this.drpMovementType.SelectedValue;
        trans.User = UserName;
        trans.Datetime = DateTime.Now;

        TransactionFacade transFacade = new TransactionFacade();
        SwMessage message = transFacade.AddTransaction(trans);
        if (message.MessageType == SwMessageType.Ok)
        {
            btnCancel_Click(sender, e);
        }


        ShowMessage(message);

    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        this.txtName.Text = string.Empty;
        this.txtQty.Text = string.Empty;
    }
    protected void InitWarehouse()
    {
        drpWarehouse.Items.Add(new ListItem("成品库", "A"));
        drpWarehouse.Items.Add(new ListItem("半成品库", "B"));
        drpWarehouse.Items.Add(new ListItem("预售库", "C"));
    }
    protected void InitLocation()
    {
        drpLocation.Items.Add(new ListItem("001", "001"));
        drpLocation.Items.Add(new ListItem("002", "002"));
    }
    protected void InitBin()
    {
        drpBin.Items.Add(new ListItem("A25", "A25"));
        drpBin.Items.Add(new ListItem("C13", "C13"));
        drpBin.Items.Add(new ListItem("D52", "D52"));
    }
    protected void InitMovementType()
    {
        MovementTypeFacade mvtFacade = new MovementTypeFacade();

        SwMovementType[] mvts = mvtFacade.GetMovementType(true);

        foreach (SwMovementType mvt in mvts)
        { 
            drpMovementType.Items.Add(new ListItem(mvt.Desc,mvt.Name));
        }
    }
}
